package st.business.tepth.business.user.busnumber.finishholder.maintain;

import java.util.List;

import st.business.tepth.base.OnDataConvertListener;
import st.business.tepth.business.bean.MaintainPassInfoBean;
import st.business.tepth.business.user.busnumber.workholder.maintain.pass.MaintainPassDataConvert;

/**
 * Author: shadow
 * Email:  1025431817@qq.com
 * Time:   2019-04-11 15:37
 */

public class FinishMaintainPresenter extends FinishMaintainContract.Presenter {
    private final FinishMaintainContract.View mView;
    private final FinishMaintainContract.Model mModel;

    public FinishMaintainPresenter(FinishMaintainContract.View view) {
        mView = view;
        mModel = new FinishMaintainModel();
    }

    @Override
    void getData(String token, int repairId, boolean isFinish) {
        addDisposable(mModel.getData(token, repairId, isFinish, new OnDataConvertListener<List<MaintainPassInfoBean>>() {
            @Override
            public void convert(List<MaintainPassInfoBean> list) {
                mView.showData(MaintainPassDataConvert.convertClassification(list));
            }

            @Override
            public void error(int code, String msg) {
                mView.showError(msg);
            }
        }));
    }

    @Override
    void rework(String token, int repairId, String repairTaskIds, String reason) {
        addDisposable(mModel.rework(token, repairId, repairTaskIds, reason,
                new OnDataConvertListener<String>() {
                    @Override
                    public void convert(String s) {
                        mView.reworkSucceed();
                    }

                    @Override
                    public void error(int code, String msg) {
                        mView.showError(msg);
                    }
                }));
    }
}
